﻿using SimpleServiceBus.Bus.MessageManagement.MessageHandling;
using SimpleServiceBus.Bus.Pipeline;
using SimpleServiceBus.Messages.Management.Monitoring;

namespace SampleMonitorClient.MessageHandlers
{
    public class EndpointStatusMessageHandler : IMessageHandler<EndpointStatusSummaryNotification>,
                                                IMessageHandler<EndpointOnlineNotification>,
                                                IMessageHandler<EndpointOfflineNotification>,
                                                IMessageHandler<EndpointStatusExpiredNotification>,
                                                IMessageHandler<EndpointErrorNotification>
    {
        #region IMessageHandler<EndpointOfflineNotification> Members

        public void Handle(EndpointOfflineNotification message,IMessageContext context)
        {
            MainForm.Current.Notify(message.EndpointID + " Offline");
        }

        #endregion

        #region IMessageHandler<EndpointOnlineNotification> Members

        public void Handle(EndpointOnlineNotification message, IMessageContext context)
        {
            MainForm.Current.Notify(message.EndpointID + " Online");
        }

        #endregion

        #region IMessageHandler<EndpointStatusExpiredNotification> Members

        public void Handle(EndpointStatusExpiredNotification message, IMessageContext context)
        {
            MainForm.Current.Notify(message.EndpointID + " HEARTBEAT EXPIRED - Offline");
        }

        #endregion

        public void Handle(EndpointStatusSummaryNotification message, IMessageContext context)
        {
            MainForm.Current.UpdateEndpointStatus(message);
        }

        public void Handle(EndpointErrorNotification message, IMessageContext context)
        {
            MainForm.Current.Notify(message.EndpointID + " experienced an exception (Failed Message ID is " + message.FailedMessageID + ":" + message.ErrorMessage);
        }
    }
}